package com.hqyj.fj.javaSpringBoot.test;

import org.junit.jupiter.api.Test;

import java.util.Stack;

public class BracketMatching {
    public  boolean IsValid(String s){
        Stack<Character> stack=new Stack<>();
        for (char c : s.toCharArray() ) {
            System.out.println();
            if (c=='['||c=='{'||c=='(')
                stack.push(c);
            else if ((c==']'||c=='}'||c==')')&&!stack.isEmpty()){
                if ( stack.pop().equals('[')&&c==']')
                    return true;
                else
                if ( stack.pop().equals('{')&&c=='}')
                    return true;
                else
                    if ( stack.pop().equals('(')&&c==')')
                    return true;

            }
            else
                return  false;

        }
        return false;
    }

    public int GetFragment (String str){
        int num=0;
        char ch=str.charAt(0);
     for (char c:str.toCharArray() ) {
         if (ch!=c)
         {
             ch=c;
             num++;
         }

 }
     return  str.length()/(num+1);
    }

    @Test
  public  void   IsValidTest(){
//        System.out.println( this.IsValid("[]{ ( }"));
        System.out.println(this.GetFragment("aaabbaaac"));
    }

    public static void main(String[] args) {

    }
}
